﻿<sap:ActivityDesigner x:Class="MyData.Activities.Designers.QueryDesigner"
    xmlns:s="clr-namespace:System;assembly=mscorlib"            
    xmlns:net="clr-namespace:System.Net;assembly=System" 
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:Model="clr-namespace:System.Activities.Presentation.Model;assembly=System.Activities.Presentation"
    xmlns:sap="clr-namespace:System.Activities.Presentation;assembly=System.Activities.Presentation"               
    xmlns:sapv="clr-namespace:System.Activities.Presentation.View;assembly=System.Activities.Presentation"
    xmlns:sapc="clr-namespace:System.Activities.Presentation.Converters;assembly=System.Activities.Presentation" 
    xmlns:local="clr-namespace:MyData.Activities;assembly=MyData.Activities"    
    xmlns:this="clr-namespace:MyData.Activities.Designers"                      
    Collapsible="True">

    <sap:ActivityDesigner.Resources>
        
        <this:ObjectConverter x:Key="objectConverter"/>

        <sapc:ModelToObjectValueConverter x:Key="ModelToObjectValueConverter" />
        <sapc:ArgumentToExpressionConverter x:Key="ArgumentToExpressionConverter" />
        <ObjectDataProvider x:Key="ComparisonOperatorEnumValues" MethodName="GetValues" ObjectType="{x:Type s:Enum}">
            <ObjectDataProvider.MethodParameters>
                <x:Type TypeName="local:ComparisonOperatorEnum" />
            </ObjectDataProvider.MethodParameters>
        </ObjectDataProvider>

        <ObjectDataProvider x:Key="SharePointTypeEnumValues" MethodName="GetValues" ObjectType="{x:Type s:Enum}">
            <ObjectDataProvider.MethodParameters>
                <x:Type TypeName="local:SharePointTypeEnum" />
            </ObjectDataProvider.MethodParameters>
        </ObjectDataProvider>
        
        <DataTemplate x:Key="ShowAsCollapsed">
            <TextBlock Foreground="Gray">
                <TextBlock.Text>
                     <MultiBinding StringFormat=" {0} = {1}">
                        <Binding Path="ModelItem.FieldRef.Expression" />
                        <Binding Path="ModelItem.Value.Expression" Converter="{StaticResource objectConverter}"/>
                    </MultiBinding>
                </TextBlock.Text>
            </TextBlock>
        </DataTemplate>
        <DataTemplate x:Key="ShowAsExpanded">
            <Grid>
                <Grid.ColumnDefinitions>
                    <ColumnDefinition />
                    <ColumnDefinition Width="20"></ColumnDefinition>
                    <ColumnDefinition />
                </Grid.ColumnDefinitions>
                <Grid.RowDefinitions>
                    <RowDefinition />
                    <RowDefinition />
                    <RowDefinition />
                    <RowDefinition />
                </Grid.RowDefinitions>

   
                <sapv:ExpressionTextBox MaxWidth="125" MinWidth="125"  HintText="Name" 
                Grid.Row ="0" Grid.Column="0"  Margin="2"
                OwnerActivity="{Binding Path=ModelItem}"
                Expression="{Binding Path=ModelItem.FieldRef, Mode=TwoWay, 
                Converter={StaticResource ArgumentToExpressionConverter}, 
                ConverterParameter=In }"
                ExpressionType="s:String" GotFocus="ExpressionTextBox_GotFocus"/>

               
               
                <ComboBox ItemsSource="{Binding Source={StaticResource ComparisonOperatorEnumValues}}" 
                          SelectedValue="{Binding Path=ModelItem.ComparisonOperator, Mode=TwoWay, 
                    Converter={StaticResource ModelToObjectValueConverter}}" VerticalAlignment="Center" Grid.Row="0" Grid.Column="2" Margin="4"></ComboBox>
                             
                <TextBlock Grid.Row ="2" Grid.Column="1" Margin="4" VerticalAlignment="Center">as</TextBlock>
                
                <sapv:ExpressionTextBox  HintText="Value" MaxWidth="125" MinWidth="125"
                Grid.Row ="2" Grid.Column="0" Grid.ColumnSpan="1" Margin="2"
                OwnerActivity="{Binding Path=ModelItem}"
                Expression="{Binding Path=ModelItem.Value, Mode=TwoWay, 
                Converter={StaticResource ArgumentToExpressionConverter}, 
                ConverterParameter=In }"
                ExpressionType="{x:Type s:Object}" GotFocus="ExpressionTextBox_GotFocus"/>
               
                <ComboBox ItemsSource="{Binding Source={StaticResource SharePointTypeEnumValues}}" 
                          SelectedValue="{Binding Path=ModelItem.ValueType, Mode=TwoWay, 
                    Converter={StaticResource ModelToObjectValueConverter}}" VerticalAlignment="Center" Grid.Row="2" Grid.Column="4" Margin="4"></ComboBox>

                <!--Next: Add LogicalOperator support -->
                <!--<TextBlock Grid.Row ="3" Grid.Column="0" Margin="4">Logical</TextBlock>
                <sapv:ExpressionTextBox  HintText="None" 
                Grid.Row ="3" Grid.Column="1" Grid.ColumnSpan="3" MaxWidth="75" MinWidth="75"  Margin="2"
                OwnerActivity="{Binding Path=ModelItem}"
                Expression="{Binding Path=ModelItem.LogicalOperator, Mode=TwoWay, 
                Converter={StaticResource ArgumentToExpressionConverter}, 
                ConverterParameter=In }"
                ExpressionType="{x:Type s:Object}" GotFocus="ExpressionTextBox_GotFocus"/>-->
                
            </Grid>
        </DataTemplate>

        <Style x:Key="StyleWithCollapse" TargetType="{x:Type ContentPresenter}">
            <Setter Property="ContentTemplate" 
                Value="{DynamicResource ShowAsExpanded}"/>
            <Style.Triggers>
                <DataTrigger Binding="{Binding Path=ShowExpanded}" Value="False">
                    <Setter Property="ContentTemplate" 
                        Value="{DynamicResource ShowAsCollapsed }"/>
                </DataTrigger>
            </Style.Triggers>
        </Style>
    </sap:ActivityDesigner.Resources>

    <sap:ActivityDesigner.Icon>
        <DrawingBrush>
            <DrawingBrush.Drawing>
                <ImageDrawing>
                    <ImageDrawing.Rect>
                        <Rect Location="0,0" Size="16,16" ></Rect>
                    </ImageDrawing.Rect>
                    <ImageDrawing.ImageSource>
                        <BitmapImage UriSource="FindItem.png" />
                    </ImageDrawing.ImageSource>
                </ImageDrawing>
            </DrawingBrush.Drawing>
        </DrawingBrush>
    </sap:ActivityDesigner.Icon>

    <Grid>
        <ContentPresenter Style="{DynamicResource StyleWithCollapse}" 
            Content="{Binding}" />
    </Grid>
</sap:ActivityDesigner>
